package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    /**
     * @param: [orders]
     * @return: void
     * @description: 新增订单
     **/
    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * @param: [ordersPageQueryDTO]
     * @return: com.github.pagehelper.Page<com.sky.entity.Orders>
     * @description: 分页查询 Order表
     **/
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * @param: [id]
     * @return: com.sky.entity.Orders
     * @description: 根据 id查询单条数据
     **/
    @Select("select * from orders where id = #{id}")
    Orders getByOrderId(Long id);

    /**
     * @param: [status, orderTime]
     * @return: java.util.List<com.sky.entity.Orders>
     * @description: 定时任务,根据时间和状态过滤
     **/
    @Select("select * from orders where status=#{status} and order_time<#{orderTime}")
    List<Orders> getByStatusAndOrderTime(Integer status, LocalDateTime orderTime);

    /**
     * @param: [map]
     * @return: java.lang.Double
     * @description: 统计营业额
     **/
    Double sumByMap(Map map);

    /**
     * @param: [map]
     * @return: java.lang.Integer
     * @description: 订单信息计数
     **/
    Integer countOrderByMap(Map map);

    /**
     * @param: [begin, end]
     * @return: java.util.List<com.sky.dto.GoodsSalesDTO>
     * @description: 统计销量前十的商品
     **/
    List<GoodsSalesDTO> getSalesTop(LocalDateTime begin, LocalDateTime end);


}
